package com.sxp.dao;

import com.sxp.model.RiceType;
import com.sxp.util.DBUtil;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class RiceDaoImpl implements RiceDao {
    @Override
    public List<RiceType> getRiceList() {
        Connection conn = null;
        List<RiceType> rl = new ArrayList<RiceType>();

        try {
            conn = DBUtil.getConnection();
            Statement stmt = conn.createStatement();
            ResultSet rSet = stmt.executeQuery("select * from rice_type");

            while (rSet.next()) {
                RiceType rt=new RiceType();
                rt.setRiceId(rSet.getInt("id"));
                rt.setRiceType(rSet.getString("type"));
                rl.add(rt);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally{
            DBUtil.closeConnection(conn);
        }

        return rl;
    }
}
